package com.tianlaiedu.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

//sqlSessionFactory-->sqlSession
public class MybatisUtil {
    private static SqlSessionFactory sqlSessionFactory;
   static  {
        try {
            //获取sqlSessionFactory对象
            InputStream in = Resources.getResourceAsStream("mybatisConfig.xml");
          sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession(true);//-->sqlSession
    }
}
